package InvestmentPojo;

import java.io.FileInputStream;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import antlr.collections.List;


public class DropDownAction extends Action{

	  public ActionForward execute(ActionMapping mapping, ActionForm inForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
		String html = "";		  	 
		String dropDownValue="";
		String forward=null;
	    String selectedValue = (String)request.getParameter("key");
	    String selectedInvestor = (String)request.getParameter("invkey");
	    int formId =(request.getParameter("formId") == null)? 1 :Integer.parseInt(request.getParameter("formId"));
	    String methodName=(String)request.getParameter("method");
	    //Starts.
	    if (selectedValue != null && !"".equals(selectedValue) && methodName != "SectorInfo") {
	    	
	    	if("4".equals(selectedInvestor) && "10".equals(selectedValue)){
	    		dropDownValue = "12";
	    	}else if("9".equals(selectedValue) || "11".equals(selectedValue) || "4".equals(selectedInvestor)){
	    		dropDownValue = "24";
	    	}else if("8".equals(selectedValue)){
	    		dropDownValue = "25";
	    	}else{
	    		dropDownValue = "12";
	    	}
	    System.out.println("This is Drop down response---"+selectedValue);	 
	    request.setAttribute("formId", formId);
	    request.setAttribute("dropDownValue", dropDownValue);
	    forward="dropDownList";
	    }//Ends.
	    if(null !=methodName && methodName.equals("SectorInfo")){
	    	String sectorvalue=(String)request.getParameter("sectorvalue");
	    	String path = request.getSession().getServletContext().getRealPath("/");
			FileInputStream fis=new FileInputStream(path+"FemaProperties/SectorConditions.properties");
	        System.out.println("InputStream is: " + fis);  
		    if(sectorvalue != null && sectorvalue !=""){
			Properties sectorpros = new Properties();
			sectorpros.load(fis);
			request.setAttribute("sectorvalue", sectorpros.getProperty(sectorvalue));
			request.setAttribute("Info", "Sector Conditions");
			
		    }
	    	forward="SUCCESS";
	    }
	    if(null !=methodName && methodName.equals("FormGuidsInfo")){
	    	String formGuideId=(String)request.getParameter("formGuideId");
	    	String path = request.getSession().getServletContext().getRealPath("/");
			FileInputStream fis=new FileInputStream(path+"FemaProperties/SectorConditions.properties");
	        System.out.println("InputStream is: " + fis);  
		    if(formGuideId != null && formGuideId !=""){
			Properties sectorpros = new Properties();
			sectorpros.load(fis);
			request.setAttribute("sectorvalue", sectorpros.getProperty(formGuideId));
			request.setAttribute("Info", "General Guidelines");
		    }
	    	forward="SUCCESS";
	    }
	    selectedValue ="";
	    return mapping.findForward(forward);

	  } // End execute()
}// End class